﻿using System;
using System.Runtime.InteropServices;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace RFEngine.Graphics
{
    [StructLayout(LayoutKind.Sequential)]
    public struct SpriteVertex
    {
        #region Fields
                
        private Vector3 _Position;
        private Color _Color;
        private Vector2 _TextureCoordinate;

        #region Static Fields

        /// <summary>
        /// Gets or Sets the vertex elements of this object.
        /// </summary>
        public static VertexElement[] VertexElements;

        #endregion

        #endregion

        #region Properties
        
        public Vector3 Position
        {
            get { return _Position; }
            set { _Position = value; }
        }

        public Color Color
        {
            get { return _Color; }
            set { _Color = value; }
        }

        public Vector2 TextureCoordinate
        {
            get { return _TextureCoordinate; }
            set { _TextureCoordinate = value; }
        }

        #region Static Properties

        public static int SizeInBytes
        {
            get { return sizeof(float) * 6; }
        }

        #endregion

        #endregion

        #region Methods

        #region Constructor(s)

        static SpriteVertex()
        {
            VertexElements = new VertexElement[]
            {
                new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0),
                new VertexElement(0, 12, VertexElementFormat.Color, VertexElementMethod.Default, VertexElementUsage.Color, 0),
                new VertexElement(0, 16, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0)
            };
        }

        /// <summary>
        /// Constructs a new instance of this object.
        /// </summary>
        /// <param name="position">The position in world space of this object.</param>
        /// <param name="color">The color of this object.</param>
        /// <param name="textureCoordinate">The texture coordinate to use for this object</param>
        public SpriteVertex(Vector3 position, Color color, Vector2 textureCoordinate)
        {
            _Color = color;
            _Position = position;
            _TextureCoordinate = textureCoordinate;
        }

        #endregion

        #endregion
    }
}
